package com.chengjue.transaction.aspect;

import com.chengjue.transaction.anno.UserAccess;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * 描述:
 * 用户检查 切面
 *
 * @author Kipeng Huang
 * @create 2018-02-27 下午2:23
 */
@Aspect
@Component
public class UserAccessAspect {
	@Pointcut(value = "@annotation(com.chengjue.transaction.anno.UserAccess)")
	public void access() {
	}

	@Before("access()")
	public void deBefore(JoinPoint joinPoint) throws Throwable {
		System.out.println("second before");
	}

	@Around("@annotation(userAccess)")
	public Object around(ProceedingJoinPoint pjp, UserAccess userAccess) {
		//获取注解里的值
		System.out.println("second around:" + userAccess.needLogin());
		try {
			return pjp.proceed();
		} catch (Throwable throwable) {
			throwable.printStackTrace();
			return null;
		}
	}
}
